package steveshrader.budget.domain;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;

import steveshrader.budget.server.BudgetService;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Vendor {
        private Long id;
        
        @PrimaryKey
        @Persistent
        private String name;
        
        @Persistent
        private String lastExpenseType;
        
        @Persistent
        private String lastPaymentType;
        
    	@NotNull
    	@DecimalMin("0")
    	private Integer version = 0;

        public Vendor() {
        }

        public Vendor(String name, String lastExpenseType, String lastPaymentType) {
            this.name = name;
            this.lastExpenseType = lastExpenseType;
            this.lastPaymentType = lastPaymentType;
        }

    	public static Vendor findVendor(Long id) {
    		return BudgetService.findVendor(id);
    	}

        public String getName() {
                return name;
        }

        public String getLastExpenseType() {
                return lastExpenseType;
        }

        public String getLastPaymentType() {
                return lastPaymentType;
        }

        public Long getId() {
                return id;
        }
        
    	public Integer getVersion() {
    		return version;
    	}
}